package com.future.controller;

import javax.validation.constraints.NotBlank;

import com.future.common.annotation.ControllerMapping;
import com.future.common.base.BaseController;
import com.future.common.exception.AppException;
import com.future.common.global.PlatFormContext;
import com.future.dao.SysUserDao;
import com.future.model.SysUser;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.plugin.activerecord.tx.Tx;

/**
 * 用户信息controller
 * 
 * @author ThinkPad
 *
 */
@ControllerMapping("/user")
public class SysUserController extends BaseController {
	@Inject
	private SysUserDao sysUserDao;
	public void getUserinfo() {
		renderResult("userinfo",this.sysUserDao.findById(PlatFormContext.getCurrentUser().getUserid()));
	};
	
	
	@Before(Tx.class)
	public void changeCurrentPassword(@NotBlank(message="旧密码为空！")String passwordold, @NotBlank(message="新密码为空！")String passwordnew){
		
		SysUser sysUser = this.sysUserDao.findById(PlatFormContext.getCurrentUser().getUserid());
		if(!sysUser.getPassword().equals(passwordold)){
			throw new AppException("旧的密码错误");
		}
		sysUser.setPassword(passwordnew);
		sysUser.update();
		renderSuccess();
	}
}
